﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.Production;
using ProduceBasicData.Api.DTO;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers
{
    /// <summary>
    /// 产线管理控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionController : ControllerBase
    {
        private readonly IMediator mediator;

        public ProductionController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 产线管理信息录入接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateProduction(CreateProductionCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 产线管理信息查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<ProductionDto>> GetProduction([FromQuery]GetProductionCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 产线管理信息更新接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateProduction(UpdateProductionCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 产线管理信息删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteProduction(DeletetProductionCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 产线管理信息批量删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeProduction(DeletetRangeProductionCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
